<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="<%=basePath%>">
<!-- 下拉框 -->
<link rel="stylesheet" href="static/ace/css/chosen.css" />
<!-- jsp文件头和头部 -->
<%@ include file="../index/top.jsp"%>
</head>
<body class="no-skin">
	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
								<form action="basearea/${msg }.do" name="baseareaForm" id="baseareaForm" method="post">
									<c:if test="${basearea.id !=null}">
					                  <input type="hidden" name="id" id="id" value="${basearea.id }" />
					                </c:if>
					                <input type="hidden" id="state" name="state" value="${state}" />
					                <input type="hidden" id="baseId" name="baseId" value="${basearea.baseId}" />
									<div id="zhongxin" style="padding-top: 13px;">
									<table id="table_report" class="table table-striped table-bordered table-hover">
										<tr>
											<td style="width:79px;text-align: right;padding-top: 13px;">区域编码:</td>
											<td><input type="text" name="code" id="code" value="${basearea.code }" maxlength="32" placeholder="这里输入区域编号" title="区域编号"  onchange="hasN()" style="width:98%;"/></td>
										</tr>
										<tr>
											<td style="width:79px;text-align: right;padding-top: 13px;">区域名称:</td>
											<td><input type="text" name="name" id="name" value="${basearea.name }" maxlength="32" placeholder="这里输入区域名称" title="区域名称"  onchange="hasU()" style="width:98%;"/></td>
										</tr>
										<tr>
											<td style="width:79px;text-align: right;padding-top: 13px;">归属基地:</td>
											<td><input type="text" name="baseName" id="baseName" value="${basearea.baseName }" readonly="readonly"  maxlength="32" placeholder="这里输入地址" title="地址" style="width:98%;"/></td>
										</tr>
									</table>
									<table id="table_report1" class="table table-striped table-bordered table-hover">										
										<tr>
											<td style="text-align: center;" colspan="10">
												<c:if test="${state =='01'}">
													<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
												</c:if>												
												<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
											</td>
										</tr>
									</table>
									</div>
									<div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
								</form>
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->
	</div>
	<!-- /.main-container -->
	<!-- basic scripts -->
	<!-- 页面底部js¨ -->
	<%@ include file="../index/foot.jsp"%>
	<!-- ace scripts -->
	<script src="static/ace/js/ace/ace.js"></script>
	<!-- inline scripts related to this page -->
	<!-- 下拉框 -->
	<script src="static/ace/js/chosen.jquery.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</body>
<script type="text/javascript">
	$(top.hangge());
	$(function(){
		 var state=$("#state").val();
		 if(state!=01){
			 $("#table_report").find("input,button,textarea,select").attr("disabled", "disabled"); 
			 /* $("#table_report1 tr:gt(0)").remove(); */
			 /* $("#table_report1").hide(); */
		 }
	});
	//保存
	function save(){
		if($("#code").val()==""){
			$("#code").tips({
				side:3,
	            msg:'请输入区域编号',
	            bg:'#AE81FF',
	            time:2
	        });
			$("#code").focus();
			return false;
		}else{
			$("#code").val($.trim($("#code").val()));
		}
		if($.trim($("#name").val())==""){
			$("#name").tips({
				side:3,
	            msg:'输入区域名称',
	            bg:'#AE81FF',
	            time:2
	        });
			$("#name").focus();
			return false;
		}else{
			$("#name").val($.trim($("#name").val()));
		}
		
		var code = $.trim($("#code").val());
		var id = $.trim($("#id").val());
		var regCode = /^[a-zA-Z0-9]+$/;
		if(code==""){
			$("#code").tips({
				side:3,
	            msg:'请输入区域编号',
	            bg:'#AE81FF',
	            time:2
	        });
			$("#code").focus();
			return false;
		}else{
			if(!regCode.test($("#code").val())){
				$("#code").tips({
					side:3,
		            msg:'区域编号长度最大为32位，只能是字母或数字组成',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#code").focus();
				return false;
			}else{
				$.ajax({
					type: "POST",
					url: '<%=basePath%>basearea/hasN.do',
			    	data: {id:id,code:code,tm:new Date().getTime()},
					dataType:'json',
					cache: false,
					success: function(data){
						 if("success" != data.result){
							 $("#code").tips({
									side:3,
						            msg:'编号 '+code+' 已存在',
						            bg:'#AE81FF',
						            time:3
						        });
							 $("#code").focus();
						 }else{
							var name = $.trim($("#name").val());
							if(name==""){
								$("#name").tips({
									side:3,
						            msg:'输入区域名称',
						            bg:'#AE81FF',
						            time:2
						        });
								$("#name").focus();
								return false;
							}else if(name.length >32){
								$("#name").tips({
									side:3,
						            msg:'区域名称最大长度为32位',
						            bg:'#AE81FF',
						            time:2
						        });
								$("#name").focus();
								return false;
							}else{
								$.ajax({
									type: "POST",
									url: '<%=basePath%>basearea/hasU.do',
							    	data: {id:id,name:name,tm:new Date().getTime()},
									dataType:'json',
									cache: false,
									success: function(data){
										if("success" != data.result){
											 $("#name").tips({
													side:3,
										            msg:'区域名称 '+name+' 已存在',
										            bg:'#AE81FF',
										            time:3
										        });
											 $("#name").focus();
										 }else{
											$("#baseareaForm").submit();
											$("#zhongxin").hide();
										    $("#zhongxin2").show(); 
										 }
									}
								});
							}
						 }
					}
				});
			}
		}
		
	}
	
	//判断区域名称是否存在
	function hasU(){		
		var name = $.trim($("#name").val());
		var id = $.trim($("#id").val());		
		if(name==""){
			$("#name").tips({
				side:3,
	            msg:'输入区域名称',
	            bg:'#AE81FF',
	            time:2
	        });
			$("#name").focus();
			return false;
		}else if(name.length >32){
			$("#name").tips({
				side:3,
	            msg:'区域名称最大长度为32位',
	            bg:'#AE81FF',
	            time:2
	        });
			$("#name").focus();
			return false;
		}else{
			$.ajax({
				type: "POST",
				url: '<%=basePath%>basearea/hasU.do',
		    	data: {id:id,name:name,tm:new Date().getTime()},
				dataType:'json',
				cache: false,
				success: function(data){
					if("success" != data.result){
						 $("#name").tips({
								side:3,
					            msg:'区域名称 '+name+' 已存在',
					            bg:'#AE81FF',
					            time:3
					        });
						 $("#name").focus();
					 }
				}
			});
		}		
	}
		
	//判断编号是否存在
	function hasN(){
		var code = $.trim($("#code").val());
		var id = $.trim($("#id").val());
		var regCode = /^[a-zA-Z0-9]+$/;
		if(code==""){
			$("#code").tips({
				side:3,
	            msg:'请输入区域编号',
	            bg:'#AE81FF',
	            time:2
	        });
			$("#code").focus();
			return false;
		}else{
			if(!regCode.test($("#code").val())){
				$("#code").tips({
					side:3,
		            msg:'区域编号长度最大为32位，只能是字母或数字组成',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#code").focus();
				return false;
			}else{
				$.ajax({
					type: "POST",
					url: '<%=basePath%>basearea/hasN.do',
			    	data: {id:id,code:code,tm:new Date().getTime()},
					dataType:'json',
					cache: false,
					success: function(data){
						 if("success" != data.result){
							 $("#code").tips({
									side:3,
						            msg:'编号 '+code+' 已存在',
						            bg:'#AE81FF',
						            time:3
						        });
							 $("#code").focus();
						 }
					}
				});
			}
		}
		
	}
</script>
</html>